package com.example.testRedis;

import com.example.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

//对 Redis 的所有操作就在这个类中完成
@Component
public class testRedis {
    @Autowired
    @Qualifier("redisTemplate1")//指定点击之后，到这里，与底层崇明的情况下，约定跳转此处。
    RedisTemplate redisTemplate;
    public void testRedisTemplate()
    {
        ValueOperations valueOperations = redisTemplate.opsForValue();

        valueOperations.set("key1", "value1");
        valueOperations.set("key2", "哈哈");

        System.out.println("testRedisTemplate...");
        System.out.println(valueOperations.get("key1"));
        System.out.println(valueOperations.get("key2"));
    }


    @Autowired
    StringRedisTemplate stringRedisTemplate;
    public void testStringRedisTemplate()
    {
        ValueOperations<String, String> stringValueOperations = stringRedisTemplate.opsForValue();
        stringValueOperations.set("key3", "value3");
        stringValueOperations.set("key4", "哈哈");

        System.out.println(stringValueOperations.get("key3"));
        System.out.println(stringValueOperations.get("key4"));
    }

    @Autowired
    RedisUtil redisUtil;
    public void testReidsUtils()
    {
        redisUtil.set("1","你好");
        redisUtil.set("2","世界！");

        System.out.println("测试redisUtil...");
        System.out.println(redisUtil.get("1"));
        System.out.println(redisUtil.get("2"));
    }
}
